package com.fr.dialog.core;

import com.fr.base.BaseUtils;
import com.fr.base.Inter;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.swing.JFileChooser;
import javax.swing.JScrollPane;
import javax.swing.filechooser.FileFilter;

public class ImageFileChooser extends JFileChooser
{
  private ImagePreviewPane imagePreviewPane = new ImagePreviewPane();
  private PropertyChangeListener imagePropertyChangeListener = new PropertyChangeListener(this)
  {
    private final ImageFileChooser this$0;

    public void propertyChange()
    {
      String str = paramPropertyChangeEvent.getPropertyName();
      if ((str.equals("SelectedFileChangedProperty")) && (this.this$0.isShowing()))
      {
        BufferedImage localBufferedImage = BaseUtils.readImage(((File)paramPropertyChangeEvent.getNewValue()).getPath());
        ImageFileChooser.access$000(this.this$0).setImage(localBufferedImage);
        ImageFileChooser.access$000(this.this$0).repaint();
      }
    }
  };

  public ImageFileChooser()
  {
    this.imagePreviewPane.setPreferredSize(new Dimension(240, 240));
    this.imagePreviewPane.addPropertyChangeListener(this.imagePropertyChangeListener);
    setAccessory(new JScrollPane(this.imagePreviewPane));
    ExampleFileFilter localExampleFileFilter = new ExampleFileFilter(this, new String[] { "jpg", "gif", "png", "bmp" }, Inter.getLocText("Image-Image_Files"));
    localExampleFileFilter.setExtensionListInDescription(true);
    addChoosableFileFilter(localExampleFileFilter);
    setAcceptAllFileFilterUsed(false);
    ChooseFileView localChooseFileView = new ChooseFileView();
    localChooseFileView.putIcon("jpg", BaseUtils.readIcon("/com/fr/dialog/images/file/jpgFile.gif"));
    localChooseFileView.putIcon("gif", BaseUtils.readIcon("/com/fr/dialog/images/file/gifFile.gif"));
    localChooseFileView.putIcon("png", BaseUtils.readIcon("/com/fr/dialog/images/file/pngFile.png"));
    localChooseFileView.putIcon("bmp", BaseUtils.readIcon("/com/fr/dialog/images/file/bmpFile.gif"));
    setFileView(localChooseFileView);
  }

  public int showDialog(Component paramComponent, String paramString)
  {
    this.imagePreviewPane.setImage(null);
    return super.showDialog(paramComponent, paramString);
  }

  static ImagePreviewPane access$000(ImageFileChooser paramImageFileChooser)
  {
    return paramImageFileChooser.imagePreviewPane;
  }

  class ExampleFileFilter extends FileFilter
  {
    private Hashtable filters;
    private String description;
    private String fullDescription;
    private boolean useExtensionsInDescription;
    private final ImageFileChooser this$0;

    public ExampleFileFilter()
    {
      this.this$0 = paramImageFileChooser;
      this.filters = null;
      this.description = null;
      this.fullDescription = null;
      this.useExtensionsInDescription = true;
      this.filters = new Hashtable();
    }

    public ExampleFileFilter(, String paramString)
    {
      this(paramImageFileChooser, paramString, null);
    }

    public ExampleFileFilter(, String paramString1, String paramString2)
    {
      this(paramImageFileChooser);
      if (paramString1 != null)
        addExtension(paramString1);
      if (paramString2 != null)
        setDescription(paramString2);
    }

    public ExampleFileFilter(, String[] paramArrayOfString)
    {
      this(paramImageFileChooser, paramArrayOfString, null);
    }

    public ExampleFileFilter(, String[] paramArrayOfString, String paramString)
    {
      this(paramImageFileChooser);
      for (int i = 0; i < paramArrayOfString.length; ++i)
        addExtension(paramArrayOfString[i]);
      if (paramString != null)
        setDescription(paramString);
    }

    public boolean accept()
    {
      if (paramFile == null)
        break label40;
      if (paramFile.isDirectory())
        return true;
      String str = getExtension(paramFile);
      label40: return ((str != null) && (this.filters.get(getExtension(paramFile)) != null));
    }

    public String getExtension()
    {
      if (paramFile != null)
      {
        String str = paramFile.getName();
        int i = str.lastIndexOf(46);
        if ((i > 0) && (i < str.length() - 1))
          return str.substring(i + 1).toLowerCase();
      }
      return null;
    }

    public void addExtension()
    {
      if (this.filters == null)
        this.filters = new Hashtable(5);
      this.filters.put(paramString.toLowerCase(), this);
      this.fullDescription = null;
    }

    public String getDescription()
    {
      if (this.fullDescription == null)
        if ((this.description == null) || (isExtensionListInDescription()))
        {
          this.fullDescription = this.description + " (";
          Enumeration localEnumeration = this.filters.keys();
          if (localEnumeration != null)
          {
            ExampleFileFilter tmp79_78 = this;
            for (tmp79_78.fullDescription = tmp79_78.fullDescription + "." + localEnumeration.nextElement(); localEnumeration.hasMoreElements(); tmp123_122.fullDescription = tmp123_122.fullDescription + ", ." + localEnumeration.nextElement())
              ExampleFileFilter tmp123_122 = this;
          }
          this.fullDescription += ")";
        }
        else
        {
          this.fullDescription = this.description;
        }
      return this.fullDescription;
    }

    public void setDescription()
    {
      this.description = paramString;
      this.fullDescription = null;
    }

    public void setExtensionListInDescription()
    {
      this.useExtensionsInDescription = paramBoolean;
      this.fullDescription = null;
    }

    public boolean isExtensionListInDescription()
    {
      return this.useExtensionsInDescription;
    }
  }
}